package com.example.zxlwork.fragmet;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.ListView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.zxlwork.adapter.GridViewMineAdapter;
import com.example.zxlwork.object.MineGridObj;
import com.example.zxlwork.object.Obj;
import com.example.zxlwork.R;
import com.example.zxlwork.adapter.ListViewMineAdapter;

import java.util.ArrayList;
import java.util.List;

public class MineFragment extends Fragment {

    //获取布局文件
    private View minePage;

    //获取listView控件对象
    private ListView lvMine;
    //初始化listview数据集合
    private List<Obj> list;
    //listview 的适配器
    private ListViewMineAdapter listViewMineAdapter;


    //获取gridview控件
    private GridView gvMine;
    //初始化gridview数据集合
    private List<MineGridObj> mineGridObj;
    //gridview的适配器
    private GridViewMineAdapter gridViewMineAdapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        //绑定布局文件
        minePage = inflater.inflate(R.layout.fragment_mine,null);


        //获取fragment_mine中的控件
        getViews();


        //给ListView中内容
        addListContents();

        //给gridview中加内容
        addGridContents();


        //实例化listView的适配器
        listViewMineAdapter = new ListViewMineAdapter(
                getActivity(),
                R.layout.fragment_mine_list_item,
                list
        );
        //绑定适配器
        lvMine.setAdapter(listViewMineAdapter);



        //实例化Gridview的适配器
        gridViewMineAdapter = new GridViewMineAdapter(
                getActivity(),
                R.layout.fragment_mine_grid_item,
                mineGridObj
        );
        //绑定适配器
        gvMine.setAdapter(gridViewMineAdapter);




        return minePage;
    }

    //给gridview中加内容
    private void addGridContents() {

        //初始化列表
        mineGridObj = new ArrayList<>();

        //初始化列表
        MineGridObj myBiji = new MineGridObj("我的笔记",R.drawable.test);
        mineGridObj.add(myBiji);
        MineGridObj myZixun = new MineGridObj("我的咨询",R.drawable.test);
        mineGridObj.add(myZixun);
        MineGridObj myGuanli = new MineGridObj("健康管理",R.drawable.test);
        mineGridObj.add(myGuanli);
        MineGridObj myQuanzi = new MineGridObj("室友圈子",R.drawable.test);
        mineGridObj.add(myQuanzi);



    }


    //给ListView中添加内容
    private void addListContents() {

        //初始化列表
        list = new ArrayList<>();

        //初始化列表内容   在这里设置listView的内容
        Obj browsingHistoy = new Obj("浏览历史",R.drawable.test);
        list.add(browsingHistoy);
        Obj inviteFriend = new Obj("邀请好友",R.drawable.test);
        list.add(inviteFriend);
        Obj helpCenter = new Obj("帮助中心",R.drawable.test);
        list.add(helpCenter);
        Obj skinSetting = new Obj("皮肤设置",R.drawable.test);
        list.add(skinSetting);
        Obj skinSetting1 = new Obj("皮肤设置",R.drawable.test);
        list.add(skinSetting1);
        Obj skinSetting2 = new Obj("皮肤设置",R.drawable.test);
        list.add(skinSetting2);
    }

    //获取fragment_mine中的控件
    private void getViews() {

        //绑定listView控件
        lvMine = minePage.findViewById(R.id.lv_mine);
        //绑定gridview控件
        gvMine = minePage.findViewById(R.id.gv_mine);
    }
}
